//
//  DMUUIDManager.m
//  yqApp
//
//  Created by PowerKing on 2017/7/23.
//  Copyright © 2017年 yq. All rights reserved.
//

#import "APUUIDManager.h"
#import "SAMKeychain.h"

static NSString *const APUUIDManagerAccount = @"DMUUID";
static NSString *const APUUIDManagerService = @"com.dianmei.uuid";

@implementation APUUIDManager

+ (NSString *)getUUID{
    return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}

+ (NSString *)readUUID{
    return [SAMKeychain passwordForService:APUUIDManagerService account:APUUIDManagerAccount];
}

+ (BOOL)saveUUID:(NSString *)UUIDString{
    return [SAMKeychain setPassword:UUIDString forService:APUUIDManagerService account:APUUIDManagerAccount];
}

+ (NSString *)dm_getUUID{
    NSString *uuid = [self readUUID];
    if (uuid) {
        return uuid;
    }else{
        NSString *uuid = [NSString stringWithFormat:@"%@",[APUUIDManager getUUID]];
        [self saveUUID:uuid];
        return uuid;
    }
}

@end
